//
//  StrategyDetailImageDetailViewController.m
//  MyDIYHouse
//
//  Created by dlios on 15-6-30.
//  Copyright (c) 2015年 李平洋. All rights reserved.
//

#import "StrategyDetailImageDetailViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

#import "StrategyModel.h"
#import "HTTPTool.h"

#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"

@interface StrategyDetailImageDetailViewController ()

//为了实现滚动,最底层加一个scrollview
@property (nonatomic,retain)UIScrollView *scrollview;

//设计师头像按钮
@property(nonatomic, retain)UIButton *headButton;
//设计师名称
@property(nonatomic, retain)UILabel *stylistName;
//房屋大图片
@property(nonatomic, retain)UIImageView *homeImageView;


//最下面的评论条
@property (nonatomic,retain)UIView *addcommentView;

@end

@implementation StrategyDetailImageDetailViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}


- (void)createData
{
    //用拼接字符串的方式,根据参数获取接口的字符串
    NSString *urlStr = [NSString stringWithFormat:@"http://api.guju.com.cn/v2/photo/%@?user=(null)",[self.urlId stringValue]];
    
    
    //   NSLog(@"%@",[self.urlId stringValue]);
    
    [HTTPTool get:urlStr body:nil httpResult:JSON success:^(id result) {
        
        
        
        
        NSDictionary *dic = result;
        StrategyModel *strategy = [[StrategyModel alloc] initWithDic:dic];
        //  NSLog(@"%@",strategy.height);
        
        NSDictionary *userDic = strategy.user;
        // NSLog(@"%@",[userDic objectForKey:@"userName"]);
        NSDictionary *userImageDic = [userDic objectForKey:@"userImage"];
        //  NSLog(@"%@",[userImageDic objectForKey:@"large"]);
        
        [self.headButton sd_setBackgroundImageWithURL:[NSURL URLWithString:[userImageDic objectForKey:@"large"]] forState:UIControlStateNormal];
        
        self.stylistName.text = [userDic objectForKey:@"userName"];
        
        NSString *picUrlStr = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w%@_h%@_m0.jpg", strategy.bId, strategy.width, strategy.height];
        //NSLog(@"%@",picUrlStr);
        
        [self.homeImageView sd_setImageWithURL:[NSURL URLWithString:picUrlStr]];
        
        self.homeImageView.frame = CGRectMake(0, 80, WIDTH, WIDTH*[strategy.height integerValue]/[strategy.width integerValue]);
        
        self.scrollview.contentSize = CGSizeMake(0, 80+self.homeImageView.frame.size.height);
        
        
        
        
        
    } failure:^(NSError *error) {
        
        //  NSLog(@"222");
        
    }];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createData];
    
    self.scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH , HEIGHT-64)];
    self.scrollview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollview];
    [self.scrollview release];
    
    
    
    //    self.addcommentView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT-64-49, WIDTH, 49)];
    //    [self.view addSubview:self.addcommentView];
    //    self.addcommentView.backgroundColor = [UIColor yellowColor];
    //    [self.addcommentView release];
#pragma mark 设计师头像按钮
    self.headButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //self.headButton.backgroundColor = [UIColor yellowColor];
    self.headButton.frame = CGRectMake(10, 17, 45, 45);
    self.headButton.layer.cornerRadius = 22.5;
    self.headButton.layer.masksToBounds = YES;
    
    //设计师头像
    
    //  [self.headButton sd_setBackgroundImageWithURL:[NSURL URLWithString:[self.matchModel.userImage objectForKey:@"large"]] forState:UIControlStateNormal];
    
    //  [self.headButton addTarget:self action:@selector(headClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollview addSubview:self.headButton];
#pragma mark 设计师名称
    self.stylistName = [[UILabel alloc] initWithFrame:CGRectMake(62, 30, 130, 20)];
    //self.stylistName.backgroundColor = [UIColor blueColor];
    [self.scrollview addSubview:self.stylistName];
    
    //传值
    // self.stylistName.text = self.matchModel.userName;
    //NSLog(@"%@",self.matchModel.userName);
    
    [_stylistName release];
#pragma mark 房屋大图片
    self.homeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 80, WIDTH, 240 )];
    //self.homeImageView.backgroundColor = [UIColor redColor];
    [self.scrollview addSubview:self.homeImageView];
    
    //传值
    // NSString *picUrlStr = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w%@_h%@_m0.jpg", self.matchModel.bId, self.matchModel.width, self.matchModel.height];
    //NSLog(@"%@",picUrlStr);
    
    //[self.homeImageView sd_setImageWithURL:[NSURL URLWithString:picUrlStr]];
    
    
    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
